<?php

namespace App\Models;

class Channel extends Base
{
    protected $table = 'channels';

    const STATUS_1 = 1;
    const STATUS_2 = 2;

    const STATUS_TEXT = array(
        self::STATUS_1 => '<span class="el-tag">正常</span>',
        self::STATUS_2 => '<span class="el-tag el-tag--danger">锁定</span>',
    );

    const TARGET_1 = 1;
    const TARGET_2 = 2;

    const TARGET_TEXT = [
        self::TARGET_1 => '<span class="el-tag">否</span>',
        self::TARGET_2 => '<span class="el-tag el-tag--danger">是</span>',
    ];

    const NOFOLLOW_1 = 1;
    const NOFOLLOW_2 = 2;

    const NOFOLLOW_TEXT = [
        self::NOFOLLOW_1 => '<span class="el-tag">无</span>',
        self::NOFOLLOW_2 => '<span class="el-tag el-tag--danger">有</span>',
    ];

    protected $fillable = [
        'id','title','rules','link','status','target','sort', 'nofollow', 'created_at', 'updated_at'
    ];



    protected function list($params = [], $fields = ['*'])
    {
        return $this->select($fields)
            ->where(function ($query) use ($params) {
                if (isset($params['kwd']) && $params['kwd']) {
                    $query->where('title', 'like', '%' . $params['kwd'] . '%')
                        ->orWhere('link', 'like', '%' . $params['kwd'] . '%');
                }
                if (isset($params['status']) && $params['status']) {
                    $query->where('status', $params['status']);
                }
            })
            ->orderBy('id', 'desc')
            ->paginate(config('setting.limit'));
    }




}
